﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using AP.LUNA.BusinessLogic;
using AP.LUNA.Commons;
using AP.LUNA.DataEntities;
using AP.LUNA.Exceptions;
using System.Web;

namespace AP.LUNA.Shell.Views
{
    public class AdministrarDesempenosComprensionPresenter : Presenter<IAdministrarDesempenosComprensionView>
    {

        // NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller
        //       The code will not work in the Shell module, as a module controller is not created by default
        //
        // private IShellController _controller;
        // public AdministrarDesempenosComprensionPresenter([CreateNew] IShellController controller)
        // {
        // 		_controller = controller;
        // }

        private BLPeriodos objPeriodos = null;
        private BLEscalas objEscalas = null;
        private HttpContext context = null;
        private BLDesempenosComprension objDesempenos = null;
        public AdministrarDesempenosComprensionPresenter()
        {
            objPeriodos = new BLPeriodos();
            objEscalas = new BLEscalas();
            objDesempenos = new BLDesempenosComprension();
            context = HttpContext.Current;
        }
        public override void OnViewLoaded()
        {
            // TODO: Implement code that will be executed every time the view loads
        }

        public override void OnViewInitialized()
        {
            List<periodos> ListP = objPeriodos.GetAll();
            ListP.Insert(0, new periodos() { Id = Constanst.CODIGO_NEGATIVO, Descripcion = Constanst.VALOR_NEGATIVO });
            List<escalas> ListE = objEscalas.GetAll();
            ListE.Insert(0, new escalas() { Id = Constanst.CODIGO_NEGATIVO, Descripcion = Constanst.VALOR_NEGATIVO });
            this.View.ListPeriodos = ListP;
            this.View.ListEscalas = ListE;
        }

        public void CargarDesempenos()
        {
            this.View.ListDesempenos = objDesempenos.GetbyAsignatura(this.View.IdAsignatura);
        }

        // TODO: Handle other view events and set state in the view

        public void Guardar()
        {
            try
            {
                desempenoscomprension d = new desempenoscomprension();
                d.Id = Guid.NewGuid();
                d.IdAsignatura = this.View.IdAsignatura;
                d.IdEscala = this.View.IdEscala;
                d.IdPeriodo = this.View.IdPeriodo;
                d.Descripcion = this.View.Descripcion;
                objDesempenos.Save(d);
                this.CargarDesempenos();
                this.View.Msgresult = UtilPresenter.ObtenerMensaje(ExceptionCode.OPERACION_EXITOSA);
                this.View.IndexView = 0;
            }
            catch (LUNAExcepcion exc)
            {
                this.View.Msgresult = UtilPresenter.ObtenerMensaje(exc.CodeError);
            }
        }
    }
}




